<?php

/**
 * WDCA - Sweet Tooth
 * 
 * NOTICE OF LICENSE
 * 
 * This source file is subject to the WDCA SWEET TOOTH POINTS AND REWARDS 
 * License, which extends the Open Software License (OSL 3.0).
 * The Sweet Tooth License is available at this URL: 
 * http://www.wdca.ca/sweet_tooth/sweet_tooth_license.txt
 * The Open Software License is available at this URL: 
 * http://opensource.org/licenses/osl-3.0.php
 * 
 * DISCLAIMER
 * 
 * By adding to, editing, or in any way modifying this code, WDCA is 
 * not held liable for any inconsistencies or abnormalities in the 
 * behaviour of this code. 
 * By adding to, editing, or in any way modifying this code, the Licensee
 * terminates any agreement of support offered by WDCA, outlined in the 
 * provided Sweet Tooth License. 
 * Upon discovery of modified code in the process of support, the Licensee 
 * is still held accountable for any and all billable time WDCA spent 
 * during the support process.
 * WDCA does not guarantee compatibility with any other framework extension. 
 * WDCA is not responsbile for any inconsistencies or abnormalities in the
 * behaviour of this code if caused by other framework extension.
 * If you did not receive a copy of the license, please send an email to 
 * contact@wdca.ca or call 1-888-699-WDCA(9322), so we can send you a copy 
 * immediately.
 * 
 *
 * @category    Cellphonezone
 * @package     Cellphonezone_Repay
 * @copyright   Copyright (c) 2011 Cellphonezone
 */

class Cellphonezone_Repay_Block_Sales_Order_Payment extends Mage_Core_Block_Template 
{
	
	public function getPaymentAmount() {
		$order = $this->getOrder ();
		$paymentAmount = (float)$order->getPaymentAmount ();		
		return !empty($paymentAmount) ? $paymentAmount : false ;
	}
	
	public function getBasePaymentAmount() {
		$order = $this->getOrder ();
		$basePaymentAmount = (float)$order->getBasePaymentAmount ();		
		return !empty($basePaymentAmount) ? $basePaymentAmount : false ;
	}
	
	public function getPaymentDescription() {
		$order = $this->getOrder ();
		$paymentDescription = $order->getPaymentDescription ();
		return $paymentDescription ? $paymentDescription : false ;
	}
	
	public function getPriceDataObject()
    {
        $obj = $this->getData('price_data_object');
        if (is_null($obj)) {
            return $this->getOrder();
        }
        return $obj;
    }
	
	public function displayPrices($basePrice, $price, $strong = false, $separator = '<br/>')
    {
        return $this->helper('adminhtml/sales')->displayPrices($this->getPriceDataObject(), $basePrice, $price, $strong, $separator);
    }
	
 	/**
     * Format total value based on order currency
     *
     * @param   Varien_Object $total
     * @return  string
     */
    public function formatValue($price)
    {
       return $this->getOrder()->formatPrice($price);
    }
	/**
	 * Fetches the order model
	 *
	 * @return TBT_Rewards_Model_Sales_Order
	 */
	public function getOrder() {
		//@nelkaake -c 14/12/10:        
		$order = null;
		$parent = $this->getParentBlock ();
		
		if ($parent) {
			$order = $parent->getOrder ();
		} elseif ($this->getData ( 'order' )) {
			$order = $this->getData ( 'order' );
		} else {
			return null;
		}
		
		if (! $order) {
			$order = Mage::registry ( 'current_order' );
		}
		return $order;
	}
	
	/**
	 * Initialize all order totals relates with tax
	 *
	 * @nelkaake Added on Thursday August 19, 2010:      
	 * @return Mage_Tax_Block_Sales_Order_Tax
	 */
	public function initTotals() {
		$parent = $this->getParentBlock ();
		$this->_order = $parent->getOrder ();
		$this->_source = $parent->getSource ();
		$parent->addTotal ( new Varien_Object ( array ('code' => 'payment', 'block_name' => 'order_payment' ) ) );
		return $this;
	}

}